package com.nidu.demo.dict.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.dict.convertor.DictDataCriteriaConvertor;
import com.nidu.demo.dict.dto.DictDataPageQry;
import com.nidu.demo.dict.convertor.DictDataConvertor;
import com.nidu.demo.dict.dto.DictDataCO;
import com.nidu.demo.dict.gateway.DictDataGateway;
import com.nidu.demo.dict.model.DictData;
import com.nidu.demo.dict.model.DictDataCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 字典类型分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class DictDataPageQryExe {

    private final DictDataGateway gateway;

    private final DictDataConvertor convertor;

    private final DictDataCriteriaConvertor criteriaConvertor;

    public PageResponse<DictDataCO> execute(DictDataPageQry qry) {
        DictDataCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<DictData> page = gateway.pageByCondition(criteria);
        List<DictDataCO> dictDataCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(dictDataCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
}